#!/usr/bin/env bash
# Pre-push hook for facet repository
# Runs clippy and doc tests before pushing to catch CI failures early
#
# Install with: cp scripts/pre-push .git/hooks/pre-push
# Or run: scripts/install-hooks

set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${YELLOW}Running pre-push checks...${NC}"

# Check formatting
echo -e "\n${YELLOW}Running cargo fmt --check...${NC}"
if ! cargo fmt --check; then
    echo -e "\n${RED}Formatting check failed!${NC}"
    echo -e "Try running: ${GREEN}cargo fmt${NC}"
    exit 1
fi

# Run clippy on all targets
echo -e "\n${YELLOW}Running cargo clippy --all-targets --all-features...${NC}"
if ! cargo clippy --all-targets --all-features -- -D warnings; then
    echo -e "\n${RED}Clippy failed!${NC}"
    echo -e "Try running: ${GREEN}cargo clippy --all-targets --all-features --fix --allow-dirty${NC}"
    exit 1
fi

# Run doc tests
echo -e "\n${YELLOW}Running cargo test --doc...${NC}"
if ! cargo test --doc; then
    echo -e "\n${RED}Doc tests failed!${NC}"
    exit 1
fi

# Run MSRV check
echo -e "\n${YELLOW}Running just msrv...${NC}"
if ! just msrv; then
    echo -e "\n${RED}MSRV check failed!${NC}"
    exit 1
fi

echo -e "\n${GREEN}All pre-push checks passed!${NC}"
